public class Solution3 {
    //724. 寻找数组的中心下标
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int[] dp = new int[n+1];
        for (int i = 0; i < n; i++) {
            dp[i+1] = dp[i] + nums[i];
        }
        for (int i = 1; i <= n; i++) {
            int l = dp[i-1];
            int r = dp[n] - dp[i];
            if (l == r) {
                return i-1;
            }
        }
        return -1;
    }
}
